package com.taa.controller;

import com.taa.entity.Product;
import com.taa.feign.ProductFeignClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;

@RefreshScope
@RestController
@RequestMapping("/consumer")
public class ConsumerController {

    @Value("${consumer.feign.timeout:3000}") // 绑定配置项，默认3000ms
    private Integer feignTimeout;

    private final ProductFeignClient feignClient;

    public ConsumerController(ProductFeignClient feignClient) {
        this.feignClient = feignClient;
    }

    @GetMapping("/products")
    public List<Product> getProducts() {
        return feignClient.getProducts();
    }

    // 新增端点用于验证配置刷新
    @GetMapping("/config")
    public Map<String, Object> showFeignConfig() {
        return Map.of(
                "currentTimeout", feignTimeout,
                "description", "该配置可通过Config Server动态修改",
                "configSource", "git仓库中的consumer-service-dev.yml"
        );
    }
}